home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / ImportRAWSample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  38.9 KB  |  1,211 lines  |  [TEXT/KAHL]

  1. /* ImportRAWSample.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "ImportRAWSample.h"
  31. #include "MainWindowStuff.h"
  32. #include "Files.h"
  33. #include "Alert.h"
  34. #include "Memory.h"
  35. #include "Screen.h"
  36. #include "TextEdit.h"
  37. #include "RadioButton.h"
  38. #include "SimpleButton.h"
  39. #include "Numbers.h"
  40. #include "Main.h"
  41. #include "Menus.h"
  42. #include "EventLoop.h"
  43. #include "SampleConsts.h"
  44. #include "BufferedFileInput.h"
  45. #include "SampleObject.h"
  46.  
  47.  
  48. #define DEFAULTSAMPLINGRATE (22050)
  49.  
  50.  
  51. typedef enum
  52.     {
  53.         eSignSigned EXECUTE(= -8542),
  54.         eSignUnsigned,
  55.         eSignSignBit
  56.     } SignModes;
  57.  
  58.  
  59. typedef enum
  60.     {
  61.         eEndianLittle EXECUTE(= -22512),
  62.         eEndianBig
  63.     } EndianType;
  64.  
  65.  
  66. /* prototype for the function that does the work. */
  67. static void                        DoImportDialog(FileType* FileDesc, MainWindowRec* MainWindow,
  68.                                                 FileSpec* WhereIsTheFile);
  69.  
  70.  
  71. /* this routine gets a file and imports it according to some generic parameters */
  72. /* that the user can specify.  any errors are handled by the routine. */
  73. void                                    ImportRAWSample(struct MainWindowRec* MainWindow)
  74.     {
  75.         FileSpec*                        WhereIsTheFile;
  76.  
  77.         CheckPtrExistence(MainWindow);
  78.         WhereIsTheFile = GetFileAny();
  79.         if (WhereIsTheFile != NIL)
  80.             {
  81.                 FileType*                        TheFileDescriptor;
  82.  
  83.                 if (OpenFile(WhereIsTheFile,&TheFileDescriptor,eReadOnly))
  84.                     {
  85.                         DoImportDialog(TheFileDescriptor,MainWindow,WhereIsTheFile);
  86.                         CloseFile(TheFileDescriptor);
  87.                     }
  88.                  else
  89.                     {
  90.                         AlertHalt("Unable to open the file.",NIL);
  91.                     }
  92.                 DisposeFileSpec(WhereIsTheFile);
  93.             }
  94.     }
  95.  
  96.  
  97. #define WINDOWXSIZE (450)
  98.  
  99. #define PROMPTX (10)
  100. #define PROMPTY (5)
  101.  
  102. #define BYTESTOSKIPPROMPTX (PROMPTX)
  103. #define BYTESTOSKIPPROMPTY (PROMPTY + 20 + 6)
  104.  
  105. #define BYTESTOSKIPEDITX (BYTESTOSKIPPROMPTX + 70)
  106. #define BYTESTOSKIPEDITY (BYTESTOSKIPPROMPTY - 3)
  107. #define BYTESTOSKIPEDITWIDTH (100)
  108. #define BYTESTOSKIPEDITHEIGHT (21)
  109.  
  110. #define SKIPBETWEENPROMPTX (BYTESTOSKIPEDITX + BYTESTOSKIPEDITWIDTH + 10)
  111. #define SKIPBETWEENPROMPTY (BYTESTOSKIPPROMPTY)
  112.  
  113. #define SKIPBETWEENEDITX (SKIPBETWEENPROMPTX + 120)
  114. #define SKIPBETWEENEDITY (BYTESTOSKIPEDITY)
  115. #define SKIPBETWEENEDITWIDTH (BYTESTOSKIPEDITWIDTH)
  116. #define SKIPBETWEENEDITHEIGHT (BYTESTOSKIPEDITHEIGHT)
  117.  
  118. #define BITSPROMPTX (PROMPTX)
  119. #define BITSPROMPTY (BYTESTOSKIPPROMPTY + BYTESTOSKIPEDITHEIGHT + 6)
  120.  
  121. #define BITS8BUTTONX (BITSPROMPTX + 100)
  122. #define BITS8BUTTONY (BITSPROMPTY - 4)
  123. #define BITS8BUTTONWIDTH (80)
  124. #define BITS8BUTTONHEIGHT (21)
  125.  
  126. #define BITS16BUTTONX (BITS8BUTTONX + BITS8BUTTONWIDTH + 10)
  127. #define BITS16BUTTONY (BITS8BUTTONY)
  128. #define BITS16BUTTONWIDTH (BITS8BUTTONWIDTH)
  129. #define BITS16BUTTONHEIGHT (BITS8BUTTONHEIGHT)
  130.  
  131. #define SIGNPROMPTX (BITSPROMPTX)
  132. #define SIGNPROMPTY (BITSPROMPTY + BITS8BUTTONHEIGHT + 3)
  133.  
  134. #define SIGNEDBUTTONX (BITS8BUTTONX)
  135. #define SIGNEDBUTTONY (SIGNPROMPTY - 4)
  136. #define SIGNEDBUTTONWIDTH (BITS8BUTTONWIDTH)
  137. #define SIGNEDBUTTONHEIGHT (BITS8BUTTONHEIGHT)
  138.  
  139. #define UNSIGNEDBUTTONX (SIGNEDBUTTONX + SIGNEDBUTTONWIDTH + 10)
  140. #define UNSIGNEDBUTTONY (SIGNEDBUTTONY)
  141. #define UNSIGNEDBUTTONWIDTH (BITS8BUTTONWIDTH)
  142. #define UNSIGNEDBUTTONHEIGHT (BITS8BUTTONHEIGHT)
  143.  
  144. #define SIGNBITBUTTONX (UNSIGNEDBUTTONX + UNSIGNEDBUTTONWIDTH + 10)
  145. #define SIGNBITBUTTONY (UNSIGNEDBUTTONY)
  146. #define SIGNBITBUTTONWIDTH (BITS8BUTTONWIDTH)
  147. #define SIGNBITBUTTONHEIGHT (BITS8BUTTONHEIGHT)
  148.  
  149. #define ENDIANPROMPTX (SIGNPROMPTX)
  150. #define ENDIANPROMPTY (SIGNPROMPTY + BITS8BUTTONHEIGHT + 3)
  151.  
  152. #define LITTLEENDIANBUTTONX (BITS8BUTTONX)
  153. #define LITTLEENDIANBUTTONY (ENDIANPROMPTY - 4)
  154. #define LITTLEENDIANBUTTONWIDTH (BITS8BUTTONWIDTH)
  155. #define LITTLEENDIANBUTTONHEIGHT (BITS8BUTTONHEIGHT)
  156.  
  157. #define BIGENDIANBUTTONX (LITTLEENDIANBUTTONX + LITTLEENDIANBUTTONWIDTH + 10)
  158. #define BIGENDIANBUTTONY (LITTLEENDIANBUTTONY)
  159. #define BIGENDIANBUTTONWIDTH (BITS8BUTTONWIDTH)
  160. #define BIGENDIANBUTTONHEIGHT (BITS8BUTTONHEIGHT)
  161.  
  162. #define NUMCHANNELSPROMPTX (ENDIANPROMPTX)
  163. #define NUMCHANNELSPROMPTY (ENDIANPROMPTY + BITS8BUTTONHEIGHT + 3)
  164.  
  165. #define NUMCHANNELSMONOBUTTONX (BITS8BUTTONX)
  166. #define NUMCHANNELSMONOBUTTONY (NUMCHANNELSPROMPTY - 4)
  167. #define NUMCHANNELSMONOBUTTONWIDTH (BITS8BUTTONWIDTH)
  168. #define NUMCHANNELSMONOBUTTONHEIGHT (BITS8BUTTONHEIGHT)
  169.  
  170. #define NUMCHANNELSSTEREOBUTTONX (NUMCHANNELSMONOBUTTONX + NUMCHANNELSMONOBUTTONWIDTH + 10)
  171. #define NUMCHANNELSSTEREOBUTTONY (NUMCHANNELSMONOBUTTONY)
  172. #define NUMCHANNELSSTEREOBUTTONWIDTH (BITS8BUTTONWIDTH)
  173. #define NUMCHANNELSSTEREOBUTTONHEIGHT (BITS8BUTTONHEIGHT)
  174.  
  175. #define FILELENGTHPROMPTX (NUMCHANNELSPROMPTX)
  176. #define FILELENGTHPROMPTY (NUMCHANNELSPROMPTY + BITS8BUTTONHEIGHT + 3)
  177.  
  178. #define FILELENGTHPLACEX (FILELENGTHPROMPTX + 80)
  179. #define FILELENGTHPLACEY (FILELENGTHPROMPTY)
  180.  
  181. #define OKBUTTONWIDTH (80)
  182. #define OKBUTTONHEIGHT (21)
  183. #define OKBUTTONX (WINDOWXSIZE / 4 - OKBUTTONWIDTH / 2)
  184. #define OKBUTTONY (FILELENGTHPLACEY + 24)
  185.  
  186. #define CANCELBUTTONWIDTH (OKBUTTONWIDTH)
  187. #define CANCELBUTTONHEIGHT (OKBUTTONHEIGHT)
  188. #define CANCELBUTTONX (3 * WINDOWXSIZE / 4 - OKBUTTONWIDTH / 2)
  189. #define CANCELBUTTONY (OKBUTTONY)
  190.  
  191. #define WINDOWYSIZE (CANCELBUTTONY + CANCELBUTTONHEIGHT + 10)
  192.  
  193.  
  194. typedef struct
  195.     {
  196.         WinType*                    ScreenID;
  197.         TextEditRec*            BytesToSkipEdit;
  198.         RadioButtonRec*        Bits8Button;
  199.         RadioButtonRec*        Bits16Button;
  200.         RadioButtonRec*        SignedButton;
  201.         RadioButtonRec*        UnsignedButton;
  202.         RadioButtonRec*        SignBitButton;
  203.         RadioButtonRec*        LittleEndian;
  204.         RadioButtonRec*        BigEndian;
  205.         RadioButtonRec*        MonoButton;
  206.         RadioButtonRec*        StereoButton;
  207.         TextEditRec*            SkipBetweenEdit;
  208.         FileType*                    FileDescriptor;
  209.         SimpleButtonRec*    OKButton;
  210.         SimpleButtonRec*    CancelButton;
  211.     } WindowRec;
  212.  
  213.  
  214. static void                        RedrawWindow(WindowRec* Window)
  215.     {
  216.         char*                                FileLengthString;
  217.  
  218.         CheckPtrExistence(Window);
  219.         TextEditFullRedraw(Window->BytesToSkipEdit);
  220.         TextEditFullRedraw(Window->SkipBetweenEdit);
  221.         RedrawRadioButton(Window->Bits8Button);
  222.         RedrawRadioButton(Window->Bits16Button);
  223.         RedrawRadioButton(Window->SignedButton);
  224.         RedrawRadioButton(Window->UnsignedButton);
  225.         RedrawRadioButton(Window->SignBitButton);
  226.         RedrawRadioButton(Window->LittleEndian);
  227.         RedrawRadioButton(Window->BigEndian);
  228.         RedrawRadioButton(Window->MonoButton);
  229.         RedrawRadioButton(Window->StereoButton);
  230.         RedrawSimpleButton(Window->OKButton);
  231.         RedrawSimpleButton(Window->CancelButton);
  232.         SetClipRect(Window->ScreenID,0,0,WINDOWXSIZE,WINDOWYSIZE);
  233.         DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Import Raw Sample:",18,
  234.             PROMPTX,PROMPTY,ePlain);
  235.         FileLengthString = IntegerToString(GetFileLength(Window->FileDescriptor));
  236.         if (FileLengthString != NIL)
  237.             {
  238.                 DrawTextLine(Window->ScreenID,GetScreenFont(),9,FileLengthString,
  239.                     PtrSize(FileLengthString),FILELENGTHPLACEX,FILELENGTHPLACEY,ePlain);
  240.                 ReleasePtr(FileLengthString);
  241.             }
  242.         DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Initial Skip:",13,
  243.             BYTESTOSKIPPROMPTX,BYTESTOSKIPPROMPTY,ePlain);
  244.         DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Skip Between Frames:",20,
  245.             SKIPBETWEENPROMPTX,SKIPBETWEENPROMPTY,ePlain);
  246.         DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Number Of Bits:",15,
  247.             BITSPROMPTX,BITSPROMPTY,ePlain);
  248.         DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Sample Sign:",12,
  249.             SIGNPROMPTX,SIGNPROMPTY,ePlain);
  250.         DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Endianness:",11,
  251.             ENDIANPROMPTX,ENDIANPROMPTY,ePlain);
  252.         DrawTextLine(Window->ScreenID,GetScreenFont(),9,"File Length:",12,
  253.             FILELENGTHPROMPTX,FILELENGTHPROMPTY,ePlain);
  254.         DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Number Of Channels:",19,
  255.             NUMCHANNELSPROMPTX,NUMCHANNELSPROMPTY,ePlain);
  256.     }
  257.  
  258.  
  259. static void                        DoImportDialog(FileType* FileDesc, MainWindowRec* MainWindow,
  260.                                                 FileSpec* WhereIsTheFile)
  261.     {
  262.         WindowRec*                    Window;
  263.         char*                                StringTemp;
  264.         MyBoolean                        LoopFlag;
  265.         MyBoolean                        DoItFlag EXECUTE(= -31342);
  266.         TextEditRec*                ActiveTextEdit;
  267.  
  268.         CheckPtrExistence(FileDesc);
  269.         CheckPtrExistence(MainWindow);
  270.  
  271.         Window = (WindowRec*)AllocPtrCanFail(sizeof(WindowRec),"DoImportDialog:  WindowRec");
  272.         if (Window == NIL)
  273.             {
  274.              FailurePoint1:
  275.                 AlertHalt("There is not enough memory available to import the sample.",NIL);
  276.                 return;
  277.             }
  278.         Window->FileDescriptor = FileDesc;
  279.  
  280.         Window->ScreenID = MakeNewWindow(eModelessDialogWindow,eWindowNotClosable,
  281.             eWindowNotZoomable,eWindowNotResizable,DialogLeftEdge(WINDOWXSIZE),
  282.             DialogTopEdge(WINDOWYSIZE),WINDOWXSIZE,WINDOWYSIZE,
  283.             (void (*)(void*))&RedrawWindow,Window);
  284.         if (Window->ScreenID == NIL)
  285.             {
  286.              FailurePoint2:
  287.                 ReleasePtr((char*)Window);
  288.                 goto FailurePoint1;
  289.             }
  290.         SetWindowName(Window->ScreenID,"Import Raw Sample");
  291.  
  292.         Window->BytesToSkipEdit = NewTextEdit(Window->ScreenID,eTENoScrollBars,
  293.             GetScreenFont(),9,BYTESTOSKIPEDITX,BYTESTOSKIPEDITY,BYTESTOSKIPEDITWIDTH,
  294.             BYTESTOSKIPEDITHEIGHT);
  295.         if (Window->BytesToSkipEdit == NIL)
  296.             {
  297.              FailurePoint3:
  298.                 KillWindow(Window->ScreenID);
  299.                 goto FailurePoint2;
  300.             }
  301.         StringTemp = IntegerToString(0);
  302.         if (StringTemp != NIL)
  303.             {
  304.                 TextEditNewRawData(Window->BytesToSkipEdit,StringTemp,SYSTEMLINEFEED);
  305.                 ReleasePtr(StringTemp);
  306.             }
  307.  
  308.         Window->SkipBetweenEdit = NewTextEdit(Window->ScreenID,eTENoScrollBars,
  309.             GetScreenFont(),9,SKIPBETWEENEDITX,SKIPBETWEENEDITY,SKIPBETWEENEDITWIDTH,
  310.             SKIPBETWEENEDITHEIGHT);
  311.         if (Window->SkipBetweenEdit == NIL)
  312.             {
  313.              FailurePoint4:
  314.                 DisposeTextEdit(Window->BytesToSkipEdit);
  315.                 goto FailurePoint3;
  316.             }
  317.         StringTemp = IntegerToString(0);
  318.         if (StringTemp != NIL)
  319.             {
  320.                 TextEditNewRawData(Window->SkipBetweenEdit,StringTemp,SYSTEMLINEFEED);
  321.                 ReleasePtr(StringTemp);
  322.             }
  323.  
  324.         Window->Bits8Button = NewRadioButton(Window->ScreenID,"8-Bit",
  325.             BITS8BUTTONX,BITS8BUTTONY,BITS8BUTTONWIDTH,BITS8BUTTONHEIGHT);
  326.         if (Window->Bits8Button == NIL)
  327.             {
  328.              FailurePoint5:
  329.                 DisposeTextEdit(Window->SkipBetweenEdit);
  330.                 goto FailurePoint4;
  331.             }
  332.         SetRadioButtonState(Window->Bits8Button,True); /* 8-bit by default */
  333.  
  334.         Window->Bits16Button = NewRadioButton(Window->ScreenID,"16-Bit",
  335.             BITS16BUTTONX,BITS16BUTTONY,BITS16BUTTONWIDTH,BITS16BUTTONHEIGHT);
  336.         if (Window->Bits16Button == NIL)
  337.             {
  338.              FailurePoint6:
  339.                 DisposeRadioButton(Window->Bits8Button);
  340.                 goto FailurePoint5;
  341.             }
  342.  
  343.         Window->SignedButton = NewRadioButton(Window->ScreenID,"Signed",
  344.             SIGNEDBUTTONX,SIGNEDBUTTONY,SIGNEDBUTTONWIDTH,SIGNEDBUTTONHEIGHT);
  345.         if (Window->SignedButton == NIL)
  346.             {
  347.              FailurePoint7:
  348.                 DisposeRadioButton(Window->Bits16Button);
  349.                 goto FailurePoint6;
  350.             }
  351.         SetRadioButtonState(Window->SignedButton,True); /* signed by default */
  352.  
  353.         Window->UnsignedButton = NewRadioButton(Window->ScreenID,"Unsigned",
  354.             UNSIGNEDBUTTONX,UNSIGNEDBUTTONY,UNSIGNEDBUTTONWIDTH,UNSIGNEDBUTTONHEIGHT);
  355.         if (Window->UnsignedButton == NIL)
  356.             {
  357.              FailurePoint8:
  358.                 DisposeRadioButton(Window->SignedButton);
  359.                 goto FailurePoint7;
  360.             }
  361.  
  362.         Window->SignBitButton = NewRadioButton(Window->ScreenID,"Sign Bit",
  363.             SIGNBITBUTTONX,SIGNBITBUTTONY,SIGNBITBUTTONWIDTH,SIGNBITBUTTONHEIGHT);
  364.         if (Window->SignBitButton == NIL)
  365.             {
  366.              FailurePoint9:
  367.                 DisposeRadioButton(Window->UnsignedButton);
  368.                 goto FailurePoint8;
  369.             }
  370.  
  371.         Window->LittleEndian = NewRadioButton(Window->ScreenID,"Little Endian",
  372.             LITTLEENDIANBUTTONX,LITTLEENDIANBUTTONY,LITTLEENDIANBUTTONWIDTH,
  373.             LITTLEENDIANBUTTONHEIGHT);
  374.         if (Window->LittleEndian == NIL)
  375.             {
  376.              FailurePoint10:
  377.                 DisposeRadioButton(Window->SignBitButton);
  378.                 goto FailurePoint9;
  379.             }
  380.         SetRadioButtonState(Window->LittleEndian,True); /* little endian by default */
  381.  
  382.         Window->BigEndian = NewRadioButton(Window->ScreenID,"Big Endian",
  383.             BIGENDIANBUTTONX,BIGENDIANBUTTONY,BIGENDIANBUTTONWIDTH,BIGENDIANBUTTONHEIGHT);
  384.         if (Window->BigEndian == NIL)
  385.             {
  386.              FailurePoint11:
  387.                 DisposeRadioButton(Window->LittleEndian);
  388.                 goto FailurePoint10;
  389.             }
  390.  
  391.         Window->OKButton = NewSimpleButton(Window->ScreenID,"OK",OKBUTTONX,OKBUTTONY,
  392.             OKBUTTONWIDTH,OKBUTTONHEIGHT);
  393.         if (Window->OKButton == NIL)
  394.             {
  395.              FailurePoint12:
  396.                 DisposeRadioButton(Window->BigEndian);
  397.                 goto FailurePoint11;
  398.             }
  399.         SetDefaultButtonState(Window->OKButton,True);
  400.  
  401.         Window->CancelButton = NewSimpleButton(Window->ScreenID,"Cancel",CANCELBUTTONX,
  402.             CANCELBUTTONY,CANCELBUTTONWIDTH,CANCELBUTTONHEIGHT);
  403.         if (Window->CancelButton == NIL)
  404.             {
  405.              FailurePoint13:
  406.                 DisposeSimpleButton(Window->OKButton);
  407.                 goto FailurePoint12;
  408.             }
  409.  
  410.         Window->MonoButton = NewRadioButton(Window->ScreenID,"Mono",NUMCHANNELSMONOBUTTONX,
  411.             NUMCHANNELSMONOBUTTONY,NUMCHANNELSMONOBUTTONWIDTH,NUMCHANNELSMONOBUTTONHEIGHT);
  412.         if (Window->MonoButton == NIL)
  413.             {
  414.              FailurePoint14:
  415.                 DisposeSimpleButton(Window->CancelButton);
  416.                 goto FailurePoint13;
  417.             }
  418.         SetRadioButtonState(Window->MonoButton,True); /* mono by default */
  419.  
  420.         Window->StereoButton = NewRadioButton(Window->ScreenID,"Stereo",
  421.             NUMCHANNELSSTEREOBUTTONX,NUMCHANNELSSTEREOBUTTONY,NUMCHANNELSSTEREOBUTTONWIDTH,
  422.             NUMCHANNELSSTEREOBUTTONHEIGHT);
  423.         if (Window->StereoButton == NIL)
  424.             {
  425.              FailurePoint15:
  426.                 DisposeRadioButton(Window->MonoButton);
  427.                 goto FailurePoint14;
  428.             }
  429.  
  430.         ActiveTextEdit = Window->BytesToSkipEdit;
  431.         EnableTextEditSelection(ActiveTextEdit);
  432.         TextEditDoMenuSelectAll(ActiveTextEdit);
  433.         LoopFlag = True;
  434.         while (LoopFlag)
  435.             {
  436.                 OrdType                            X;
  437.                 OrdType                            Y;
  438.                 ModifierFlags                Modifiers;
  439.                 MenuItemType*                MenuItem;
  440.                 char                                KeyPress;
  441.  
  442.                 switch (GetAnEvent(&X,&Y,&Modifiers,NIL,&MenuItem,&KeyPress))
  443.                     {
  444.                         default:
  445.                             break;
  446.                         case eCheckCursor:
  447.                             if (TextEditIBeamTest(Window->BytesToSkipEdit,X,Y)
  448.                                 || TextEditIBeamTest(Window->SkipBetweenEdit,X,Y))
  449.                                 {
  450.                                     SetIBeamCursor();
  451.                                 }
  452.                              else
  453.                                 {
  454.                                     SetArrowCursor();
  455.                                 }
  456.                             goto UpdateCursorPoint;
  457.                             break;
  458.                         case eNoEvent:
  459.                          UpdateCursorPoint:
  460.                             TextEditUpdateCursor(ActiveTextEdit);
  461.                             break;
  462.                         case eMenuStarting:
  463.                             EnableMenuItem(mPaste);
  464.                             if (TextEditIsThereValidSelection(ActiveTextEdit))
  465.                                 {
  466.                                     EnableMenuItem(mCut);
  467.                                     EnableMenuItem(mCopy);
  468.                                     EnableMenuItem(mClear);
  469.                                 }
  470.                             EnableMenuItem(mSelectAll);
  471.                             if (TextEditCanWeUndo(ActiveTextEdit))
  472.                                 {
  473.                                     EnableMenuItem(mUndo);
  474.                                 }
  475.                             break;
  476.                         case eMenuCommand:
  477.                             if (MenuItem == mPaste)
  478.                                 {
  479.                                     TextEditDoMenuPaste(ActiveTextEdit);
  480.                                 }
  481.                             else if (MenuItem == mCut)
  482.                                 {
  483.                                     TextEditDoMenuCut(ActiveTextEdit);
  484.                                 }
  485.                             else if (MenuItem == mCopy)
  486.                                 {
  487.                                     TextEditDoMenuCopy(ActiveTextEdit);
  488.                                 }
  489.                             else if (MenuItem == mClear)
  490.                                 {
  491.                                     TextEditDoMenuClear(ActiveTextEdit);
  492.                                 }
  493.                             else if (MenuItem == mUndo)
  494.                                 {
  495.                                     TextEditDoMenuUndo(ActiveTextEdit);
  496.                                     TextEditShowSelection(ActiveTextEdit);
  497.                                 }
  498.                             else if (MenuItem == mSelectAll)
  499.                                 {
  500.                                     TextEditDoMenuSelectAll(ActiveTextEdit);
  501.                                 }
  502.                             else
  503.                                 {
  504.                                     EXECUTE(PRERR(AllowResume,
  505.                                         "DoImportDialog: Undefined menu option chosen"));
  506.                                 }
  507.                             break;
  508.                         case eKeyPressed:
  509.                             if (KeyPress == 13)
  510.                                 {
  511.                                     FlashButton(Window->OKButton);
  512.                                     DoItFlag = True;
  513.                                     LoopFlag = False;
  514.                                 }
  515.                             else if (KeyPress == 9)
  516.                                 {
  517.                                     DisableTextEditSelection(ActiveTextEdit);
  518.                                     if (ActiveTextEdit == Window->BytesToSkipEdit)
  519.                                         {
  520.                                             ActiveTextEdit = Window->SkipBetweenEdit;
  521.                                         }
  522.                                      else
  523.                                         {
  524.                                             ActiveTextEdit = Window->BytesToSkipEdit;
  525.                                         }
  526.                                     TextEditDoMenuSelectAll(ActiveTextEdit);
  527.                                     EnableTextEditSelection(ActiveTextEdit);
  528.                                 }
  529.                             else if (KeyPress == eCancelKey)
  530.                                 {
  531.                                     FlashButton(Window->CancelButton);
  532.                                     DoItFlag = False;
  533.                                     LoopFlag = False;
  534.                                 }
  535.                             else
  536.                                 {
  537.                                     TextEditDoKeyPressed(ActiveTextEdit,KeyPress,Modifiers);
  538.                                 }
  539.                             break;
  540.                         case eMouseDown:
  541.                             if (SimpleButtonHitTest(Window->OKButton,X,Y))
  542.                                 {
  543.                                     if (SimpleButtonMouseDown(Window->OKButton,X,Y,NIL,NIL))
  544.                                         {
  545.                                             DoItFlag = True;
  546.                                             LoopFlag = False;
  547.                                         }
  548.                                 }
  549.                             else if (SimpleButtonHitTest(Window->CancelButton,X,Y))
  550.                                 {
  551.                                     if (SimpleButtonMouseDown(Window->CancelButton,X,Y,NIL,NIL))
  552.                                         {
  553.                                             DoItFlag = False;
  554.                                             LoopFlag = False;
  555.                                         }
  556.                                 }
  557.                             else if (TextEditHitTest(Window->SkipBetweenEdit,X,Y))
  558.                                 {
  559.                                     if (ActiveTextEdit != Window->SkipBetweenEdit)
  560.                                         {
  561.                                             DisableTextEditSelection(ActiveTextEdit);
  562.                                             ActiveTextEdit = Window->SkipBetweenEdit;
  563.                                             EnableTextEditSelection(ActiveTextEdit);
  564.                                         }
  565.                                     TextEditDoMouseDown(ActiveTextEdit,X,Y,Modifiers);
  566.                                 }
  567.                             else if (TextEditHitTest(Window->BytesToSkipEdit,X,Y))
  568.                                 {
  569.                                     if (ActiveTextEdit != Window->BytesToSkipEdit)
  570.                                         {
  571.                                             DisableTextEditSelection(ActiveTextEdit);
  572.                                             ActiveTextEdit = Window->BytesToSkipEdit;
  573.                                             EnableTextEditSelection(ActiveTextEdit);
  574.                                         }
  575.                                     TextEditDoMouseDown(ActiveTextEdit,X,Y,Modifiers);
  576.                                 }
  577.                             else if (RadioButtonHitTest(Window->Bits8Button,X,Y))
  578.                                 {
  579.                                     if (RadioButtonMouseDown(Window->Bits8Button,X,Y))
  580.                                         {
  581.                                             SetRadioButtonState(Window->Bits16Button,False);
  582.                                         }
  583.                                 }
  584.                             else if (RadioButtonHitTest(Window->Bits16Button,X,Y))
  585.                                 {
  586.                                     if (RadioButtonMouseDown(Window->Bits16Button,X,Y))
  587.                                         {
  588.                                             SetRadioButtonState(Window->Bits8Button,False);
  589.                                         }
  590.                                 }
  591.                             else if (RadioButtonHitTest(Window->SignedButton,X,Y))
  592.                                 {
  593.                                     if (RadioButtonMouseDown(Window->SignedButton,X,Y))
  594.                                         {
  595.                                             SetRadioButtonState(Window->UnsignedButton,False);
  596.                                             SetRadioButtonState(Window->SignBitButton,False);
  597.                                         }
  598.                                 }
  599.                             else if (RadioButtonHitTest(Window->UnsignedButton,X,Y))
  600.                                 {
  601.                                     if (RadioButtonMouseDown(Window->UnsignedButton,X,Y))
  602.                                         {
  603.                                             SetRadioButtonState(Window->SignedButton,False);
  604.                                             SetRadioButtonState(Window->SignBitButton,False);
  605.                                         }
  606.                                 }
  607.                             else if (RadioButtonHitTest(Window->SignBitButton,X,Y))
  608.                                 {
  609.                                     if (RadioButtonMouseDown(Window->SignBitButton,X,Y))
  610.                                         {
  611.                                             SetRadioButtonState(Window->SignedButton,False);
  612.                                             SetRadioButtonState(Window->UnsignedButton,False);
  613.                                         }
  614.                                 }
  615.                             else if (RadioButtonHitTest(Window->LittleEndian,X,Y))
  616.                                 {
  617.                                     if (RadioButtonMouseDown(Window->LittleEndian,X,Y))
  618.                                         {
  619.                                             SetRadioButtonState(Window->BigEndian,False);
  620.                                         }
  621.                                 }
  622.                             else if (RadioButtonHitTest(Window->BigEndian,X,Y))
  623.                                 {
  624.                                     if (RadioButtonMouseDown(Window->BigEndian,X,Y))
  625.                                         {
  626.                                             SetRadioButtonState(Window->LittleEndian,False);
  627.                                         }
  628.                                 }
  629.                             else if (RadioButtonHitTest(Window->MonoButton,X,Y))
  630.                                 {
  631.                                     if (RadioButtonMouseDown(Window->MonoButton,X,Y))
  632.                                         {
  633.                                             SetRadioButtonState(Window->StereoButton,False);
  634.                                         }
  635.                                 }
  636.                             else if (RadioButtonHitTest(Window->StereoButton,X,Y))
  637.                                 {
  638.                                     if (RadioButtonMouseDown(Window->StereoButton,X,Y))
  639.                                         {
  640.                                             SetRadioButtonState(Window->MonoButton,False);
  641.                                         }
  642.                                 }
  643.                             break;
  644.                     }
  645.             }
  646.         ERROR((DoItFlag != True) && (DoItFlag != False),PRERR(ForceAbort,
  647.             "DoImportDialog:  DoItFlag is neither true nor false"));
  648.  
  649.         if (DoItFlag)
  650.             {
  651.                 NumBitsType                NumBits;
  652.                 NumChannelsType        NumChannels;
  653.                 SignModes                    SigningMode;
  654.                 EndianType                Endianness;
  655.                 long                            FramePadding;
  656.                 long                            InitialSkip;
  657.                 BufferedInputRec*    File;
  658.                 SampleObjectRec*    ReturnedSampleObject;
  659.  
  660.                 StringTemp = TextEditGetRawData(Window->BytesToSkipEdit,SYSTEMLINEFEED);
  661.                 if (StringTemp == NIL)
  662.                     {
  663.                         AlertHalt("There is not enough memory available to import the sample.",NIL);
  664.                         goto DoItFailedPoint;
  665.                     }
  666.                 InitialSkip = StringToInteger(StringTemp,PtrSize(StringTemp));
  667.                 ReleasePtr(StringTemp);
  668.  
  669.                 StringTemp = TextEditGetRawData(Window->SkipBetweenEdit,SYSTEMLINEFEED);
  670.                 if (StringTemp == NIL)
  671.                     {
  672.                         AlertHalt("There is not enough memory available to import the sample.",NIL);
  673.                         goto DoItFailedPoint;
  674.                     }
  675.                 FramePadding = StringToInteger(StringTemp,PtrSize(StringTemp));
  676.                 ReleasePtr(StringTemp);
  677.  
  678.                 if (GetRadioButtonState(Window->Bits8Button))
  679.                     {
  680.                         NumBits = eSample8bit;
  681.                     }
  682.                 else if (GetRadioButtonState(Window->Bits16Button))
  683.                     {
  684.                         NumBits = eSample16bit;
  685.                     }
  686.                 else
  687.                     {
  688.                         EXECUTE(PRERR(AllowResume,"DoImportDialog:  bits radio button problem"));
  689.                     }
  690.  
  691.                 if (GetRadioButtonState(Window->SignedButton))
  692.                     {
  693.                         SigningMode = eSignSigned;
  694.                     }
  695.                 else if (GetRadioButtonState(Window->UnsignedButton))
  696.                     {
  697.                         SigningMode = eSignUnsigned;
  698.                     }
  699.                 else if (GetRadioButtonState(Window->SignBitButton))
  700.                     {
  701.                         SigningMode = eSignSignBit;
  702.                     }
  703.                 else
  704.                     {
  705.                         EXECUTE(PRERR(AllowResume,"DoImportDialog:  sign radio button problem"));
  706.                     }
  707.  
  708.                 if (GetRadioButtonState(Window->LittleEndian))
  709.                     {
  710.                         Endianness = eEndianLittle;
  711.                     }
  712.                 else if (GetRadioButtonState(Window->BigEndian))
  713.                     {
  714.                         Endianness = eEndianBig;
  715.                     }
  716.                 else
  717.                     {
  718.                         EXECUTE(PRERR(AllowResume,"DoImportDialog:  endianness radio button problem"));
  719.                     }
  720.  
  721.                 if (GetRadioButtonState(Window->MonoButton))
  722.                     {
  723.                         NumChannels = eSampleMono;
  724.                     }
  725.                 else if (GetRadioButtonState(Window->StereoButton))
  726.                     {
  727.                         NumChannels = eSampleStereo;
  728.                     }
  729.                 else
  730.                     {
  731.                         EXECUTE(PRERR(AllowResume,"DoImportDialog:  channels radio button problem"));
  732.                     }
  733.  
  734.                 if (GetFileLength(FileDesc) <= InitialSkip)
  735.                     {
  736.                         AlertHalt("Initial skip value skipped entire file.",NIL);
  737.                         goto DoItFailedPoint;
  738.                     }
  739.                 if (!SetFilePosition(FileDesc,InitialSkip))
  740.                     {
  741.                         AlertHalt("Unable to read from the file.",NIL);
  742.                         goto DoItFailedPoint;
  743.                     }
  744.                 File = NewBufferedInput(FileDesc);
  745.                 if (File == NIL)
  746.                     {
  747.                         AlertHalt("There is not enough memory available to import the sample.",NIL);
  748.                         goto DoItFailedPoint;
  749.                     }
  750.                 switch (NumChannels)
  751.                     {
  752.                         default:
  753.                             EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad num channels"));
  754.                             break;
  755.                         case eSampleMono:
  756.                             switch (NumBits)
  757.                                 {
  758.                                     default:
  759.                                         EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad num bits"));
  760.                                         break;
  761.                                     case eSample8bit:
  762.                                         {
  763.                                             signed char*        Sample;
  764.                                             long                        NumFrames;
  765.                                             long                        Scan;
  766.  
  767.                                             NumFrames = (GetFileLength(FileDesc) - InitialSkip)
  768.                                                 / (1 + FramePadding);
  769.                                             Sample = (signed char*)AllocPtrCanFail(NumFrames,
  770.                                                 "DoImportDialog[RAW]:  Sample");
  771.                                             if (Sample == NIL)
  772.                                                 {
  773.                                                     EndBufferedInput(File);
  774.                                                     AlertHalt("There is not enough memory available to import "
  775.                                                         "the sample.",NIL);
  776.                                                     goto DoItFailedPoint;
  777.                                                 }
  778.                                             for (Scan = 0; Scan < NumFrames; Scan += 1)
  779.                                                 {
  780.                                                     unsigned char        TheValue;
  781.                                                     long                        Index;
  782.  
  783.                                                     if (!ReadBufferedUnsignedChar(File,&TheValue))
  784.                                                         {
  785.                                                             ReleasePtr((char*)Sample);
  786.                                                             EndBufferedInput(File);
  787.                                                             AlertHalt("Unable to read from the file.",NIL);
  788.                                                             goto DoItFailedPoint;
  789.                                                         }
  790.                                                     PRNGCHK(Sample,&(Sample[Scan]),sizeof(Sample[Scan]));
  791.                                                     switch (SigningMode)
  792.                                                         {
  793.                                                             default:
  794.                                                                 EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad sign mode"));
  795.                                                                 break;
  796.                                                             case eSignSigned:
  797.                                                                 if ((TheValue & 0x80) != 0)
  798.                                                                     {
  799.                                                                         Sample[Scan] = (TheValue & 0x7f) | ~0x7f;
  800.                                                                     }
  801.                                                                  else
  802.                                                                     {
  803.                                                                         Sample[Scan] = TheValue & 0x7f;
  804.                                                                     }
  805.                                                                 break;
  806.                                                             case eSignUnsigned:
  807.                                                                 Sample[Scan] = (TheValue & 0xff) - 128;
  808.                                                                 break;
  809.                                                             case eSignSignBit:
  810.                                                                 if ((TheValue & 0x80) != 0)
  811.                                                                     {
  812.                                                                         Sample[Scan] = -(TheValue & 0x7f);
  813.                                                                     }
  814.                                                                  else
  815.                                                                     {
  816.                                                                         Sample[Scan] = TheValue & 0x7f;
  817.                                                                     }
  818.                                                                 break;
  819.                                                         }
  820.                                                     for (Index = 0; Index < FramePadding; Index += 1)
  821.                                                         {
  822.                                                             unsigned char                    Stupid;
  823.  
  824.                                                             if (!ReadBufferedUnsignedChar(File,&Stupid))
  825.                                                                 {
  826.                                                                     ReleasePtr((char*)Sample);
  827.                                                                     EndBufferedInput(File);
  828.                                                                     AlertHalt("Unable to read from the file.",NIL);
  829.                                                                     goto DoItFailedPoint;
  830.                                                                 }
  831.                                                         }
  832.                                                 }
  833.                                             ReturnedSampleObject = MainWindowCopyRawSampleAndOpen(MainWindow,
  834.                                                 (char*)Sample,NumBits,NumChannels,0,0,0,0,0,0,0,
  835.                                                 DEFAULTSAMPLINGRATE,261.625565300598635);
  836.                                             ReleasePtr((char*)Sample);
  837.                                         }
  838.                                         break;
  839.                                     case eSample16bit:
  840.                                         {
  841.                                             signed short*        Sample;
  842.                                             long                        NumFrames;
  843.                                             long                        Scan;
  844.  
  845.                                             NumFrames = (GetFileLength(FileDesc) - InitialSkip)
  846.                                                 / (2 + FramePadding);
  847.                                             Sample = (signed short*)AllocPtrCanFail(NumFrames * sizeof(short),
  848.                                                 "DoImportDialog[RAW]:  Sample");
  849.                                             if (Sample == NIL)
  850.                                                 {
  851.                                                     EndBufferedInput(File);
  852.                                                     AlertHalt("There is not enough memory available to import "
  853.                                                         "the sample.",NIL);
  854.                                                     goto DoItFailedPoint;
  855.                                                 }
  856.                                             for (Scan = 0; Scan < NumFrames; Scan += 1)
  857.                                                 {
  858.                                                     unsigned short    TheValue;
  859.                                                     long                        Index;
  860.  
  861.                                                     switch (Endianness)
  862.                                                         {
  863.                                                             default:
  864.                                                                 EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad endianness"));
  865.                                                                 break;
  866.                                                             case eEndianLittle:
  867.                                                                 if (!ReadBufferedUnsignedShortLittleEndian(File,&TheValue))
  868.                                                                     {
  869.                                                                         ReleasePtr((char*)Sample);
  870.                                                                         EndBufferedInput(File);
  871.                                                                         AlertHalt("Unable to read from the file.",NIL);
  872.                                                                         goto DoItFailedPoint;
  873.                                                                     }
  874.                                                                 break;
  875.                                                             case eEndianBig:
  876.                                                                 if (!ReadBufferedUnsignedShortBigEndian(File,&TheValue))
  877.                                                                     {
  878.                                                                         ReleasePtr((char*)Sample);
  879.                                                                         EndBufferedInput(File);
  880.                                                                         AlertHalt("Unable to read from the file.",NIL);
  881.                                                                         goto DoItFailedPoint;
  882.                                                                     }
  883.                                                                 break;
  884.                                                         }
  885.                                                     PRNGCHK(Sample,&(Sample[Scan]),sizeof(Sample[Scan]));
  886.                                                     switch (SigningMode)
  887.                                                         {
  888.                                                             default:
  889.                                                                 EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad sign mode"));
  890.                                                                 break;
  891.                                                             case eSignSigned:
  892.                                                                 if ((TheValue & 0x8000) != 0)
  893.                                                                     {
  894.                                                                         Sample[Scan] = (TheValue & 0x7fff) | ~0x7fff;
  895.                                                                     }
  896.                                                                  else
  897.                                                                     {
  898.                                                                         Sample[Scan] = TheValue & 0x7fff;
  899.                                                                     }
  900.                                                                 break;
  901.                                                             case eSignUnsigned:
  902.                                                                 Sample[Scan] = (TheValue & 0xffff) - 32768;
  903.                                                                 break;
  904.                                                             case eSignSignBit:
  905.                                                                 if ((TheValue & 0x8000) != 0)
  906.                                                                     {
  907.                                                                         Sample[Scan] = -(TheValue & 0x7fff);
  908.                                                                     }
  909.                                                                  else
  910.                                                                     {
  911.                                                                         Sample[Scan] = TheValue & 0x7fff;
  912.                                                                     }
  913.                                                                 break;
  914.                                                         }
  915.                                                     for (Index = 0; Index < FramePadding; Index += 1)
  916.                                                         {
  917.                                                             unsigned char                    Stupid;
  918.  
  919.                                                             if (!ReadBufferedUnsignedChar(File,&Stupid))
  920.                                                                 {
  921.                                                                     ReleasePtr((char*)Sample);
  922.                                                                     EndBufferedInput(File);
  923.                                                                     AlertHalt("Unable to read from the file.",NIL);
  924.                                                                     goto DoItFailedPoint;
  925.                                                                 }
  926.                                                         }
  927.                                                 }
  928.                                             ReturnedSampleObject = MainWindowCopyRawSampleAndOpen(MainWindow,
  929.                                                 (char*)Sample,NumBits,NumChannels,0,0,0,0,0,0,0,
  930.                                                 DEFAULTSAMPLINGRATE,261.625565300598635);
  931.                                             ReleasePtr((char*)Sample);
  932.                                         }
  933.                                         break;
  934.                                 }
  935.                             break;
  936.                         case eSampleStereo:
  937.                             switch (NumBits)
  938.                                 {
  939.                                     default:
  940.                                         EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad num bits"));
  941.                                         break;
  942.                                     case eSample8bit:
  943.                                         {
  944.                                             signed char*        Sample;
  945.                                             long                        NumFrames;
  946.                                             long                        Scan;
  947.  
  948.                                             NumFrames = (GetFileLength(FileDesc) - InitialSkip)
  949.                                                 / (2 + FramePadding);
  950.                                             Sample = (signed char*)AllocPtrCanFail(NumFrames * 2,
  951.                                                 "DoImportDialog[RAW]:  Sample");
  952.                                             if (Sample == NIL)
  953.                                                 {
  954.                                                     EndBufferedInput(File);
  955.                                                     AlertHalt("There is not enough memory available to import "
  956.                                                         "the sample.",NIL);
  957.                                                     goto DoItFailedPoint;
  958.                                                 }
  959.                                             for (Scan = 0; Scan < NumFrames; Scan += 2)
  960.                                                 {
  961.                                                     unsigned char        LeftValue;
  962.                                                     unsigned char        RightValue;
  963.                                                     long                        Index;
  964.  
  965.                                                     if (!ReadBufferedUnsignedChar(File,&LeftValue))
  966.                                                         {
  967.                                                             ReleasePtr((char*)Sample);
  968.                                                             EndBufferedInput(File);
  969.                                                             AlertHalt("Unable to read from the file.",NIL);
  970.                                                             goto DoItFailedPoint;
  971.                                                         }
  972.                                                     if (!ReadBufferedUnsignedChar(File,&RightValue))
  973.                                                         {
  974.                                                             ReleasePtr((char*)Sample);
  975.                                                             EndBufferedInput(File);
  976.                                                             AlertHalt("Unable to read from the file.",NIL);
  977.                                                             goto DoItFailedPoint;
  978.                                                         }
  979.                                                     PRNGCHK(Sample,&(Sample[Scan]),sizeof(Sample[Scan]));
  980.                                                     PRNGCHK(Sample,&(Sample[Scan + 1]),sizeof(Sample[Scan + 1]));
  981.                                                     switch (SigningMode)
  982.                                                         {
  983.                                                             default:
  984.                                                                 EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad sign mode"));
  985.                                                                 break;
  986.                                                             case eSignSigned:
  987.                                                                 if ((LeftValue & 0x80) != 0)
  988.                                                                     {
  989.                                                                         Sample[Scan] = (LeftValue & 0x7f) | ~0x7f;
  990.                                                                     }
  991.                                                                  else
  992.                                                                     {
  993.                                                                         Sample[Scan] = LeftValue & 0x7f;
  994.                                                                     }
  995.                                                                 if ((RightValue & 0x80) != 0)
  996.                                                                     {
  997.                                                                         Sample[Scan + 1] = (RightValue & 0x7f) | ~0x7f;
  998.                                                                     }
  999.                                                                  else
  1000.                                                                     {
  1001.                                                                         Sample[Scan + 1] = RightValue & 0x7f;
  1002.                                                                     }
  1003.                                                                 break;
  1004.                                                             case eSignUnsigned:
  1005.                                                                 Sample[Scan] = (LeftValue & 0xff) - 128;
  1006.                                                                 Sample[Scan + 1] = (RightValue & 0xff) - 128;
  1007.                                                                 break;
  1008.                                                             case eSignSignBit:
  1009.                                                                 if ((LeftValue & 0x80) != 0)
  1010.                                                                     {
  1011.                                                                         Sample[Scan] = -(LeftValue & 0x7f);
  1012.                                                                     }
  1013.                                                                  else
  1014.                                                                     {
  1015.                                                                         Sample[Scan] = LeftValue & 0x7f;
  1016.                                                                     }
  1017.                                                                 if ((RightValue & 0x80) != 0)
  1018.                                                                     {
  1019.                                                                         Sample[Scan + 1] = -(RightValue & 0x7f);
  1020.                                                                     }
  1021.                                                                  else
  1022.                                                                     {
  1023.                                                                         Sample[Scan + 1] = RightValue & 0x7f;
  1024.                                                                     }
  1025.                                                                 break;
  1026.                                                         }
  1027.                                                     for (Index = 0; Index < FramePadding; Index += 1)
  1028.                                                         {
  1029.                                                             unsigned char                    Stupid;
  1030.  
  1031.                                                             if (!ReadBufferedUnsignedChar(File,&Stupid))
  1032.                                                                 {
  1033.                                                                     ReleasePtr((char*)Sample);
  1034.                                                                     EndBufferedInput(File);
  1035.                                                                     AlertHalt("Unable to read from the file.",NIL);
  1036.                                                                     goto DoItFailedPoint;
  1037.                                                                 }
  1038.                                                         }
  1039.                                                 }
  1040.                                             ReturnedSampleObject = MainWindowCopyRawSampleAndOpen(MainWindow,
  1041.                                                 (char*)Sample,NumBits,NumChannels,0,0,0,0,0,0,0,
  1042.                                                 DEFAULTSAMPLINGRATE,261.625565300598635);
  1043.                                             ReleasePtr((char*)Sample);
  1044.                                         }
  1045.                                         break;
  1046.                                     case eSample16bit:
  1047.                                         {
  1048.                                             signed short*        Sample;
  1049.                                             long                        NumFrames;
  1050.                                             long                        Scan;
  1051.  
  1052.                                             NumFrames = (GetFileLength(FileDesc) - InitialSkip)
  1053.                                                 / (4 + FramePadding);
  1054.                                             Sample = (signed short*)AllocPtrCanFail(NumFrames * 2 * sizeof(short),
  1055.                                                 "DoImportDialog[RAW]:  Sample");
  1056.                                             if (Sample == NIL)
  1057.                                                 {
  1058.                                                     EndBufferedInput(File);
  1059.                                                     AlertHalt("There is not enough memory available to import "
  1060.                                                         "the sample.",NIL);
  1061.                                                     goto DoItFailedPoint;
  1062.                                                 }
  1063.                                             for (Scan = 0; Scan < NumFrames; Scan += 2)
  1064.                                                 {
  1065.                                                     unsigned short    LeftValue;
  1066.                                                     unsigned short    RightValue;
  1067.                                                     long                        Index;
  1068.  
  1069.                                                     switch (Endianness)
  1070.                                                         {
  1071.                                                             default:
  1072.                                                                 EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad endianness"));
  1073.                                                                 break;
  1074.                                                             case eEndianLittle:
  1075.                                                                 if (!ReadBufferedUnsignedShortLittleEndian(File,&LeftValue))
  1076.                                                                     {
  1077.                                                                         ReleasePtr((char*)Sample);
  1078.                                                                         EndBufferedInput(File);
  1079.                                                                         AlertHalt("Unable to read from the file.",NIL);
  1080.                                                                         goto DoItFailedPoint;
  1081.                                                                     }
  1082.                                                                 if (!ReadBufferedUnsignedShortLittleEndian(File,&RightValue))
  1083.                                                                     {
  1084.                                                                         ReleasePtr((char*)Sample);
  1085.                                                                         EndBufferedInput(File);
  1086.                                                                         AlertHalt("Unable to read from the file.",NIL);
  1087.                                                                         goto DoItFailedPoint;
  1088.                                                                     }
  1089.                                                                 break;
  1090.                                                             case eEndianBig:
  1091.                                                                 if (!ReadBufferedUnsignedShortBigEndian(File,&LeftValue))
  1092.                                                                     {
  1093.                                                                         ReleasePtr((char*)Sample);
  1094.                                                                         EndBufferedInput(File);
  1095.                                                                         AlertHalt("Unable to read from the file.",NIL);
  1096.                                                                         goto DoItFailedPoint;
  1097.                                                                     }
  1098.                                                                 if (!ReadBufferedUnsignedShortBigEndian(File,&RightValue))
  1099.                                                                     {
  1100.                                                                         ReleasePtr((char*)Sample);
  1101.                                                                         EndBufferedInput(File);
  1102.                                                                         AlertHalt("Unable to read from the file.",NIL);
  1103.                                                                         goto DoItFailedPoint;
  1104.                                                                     }
  1105.                                                                 break;
  1106.                                                         }
  1107.                                                     PRNGCHK(Sample,&(Sample[Scan]),sizeof(Sample[Scan]));
  1108.                                                     PRNGCHK(Sample,&(Sample[Scan + 1]),sizeof(Sample[Scan + 1]));
  1109.                                                     switch (SigningMode)
  1110.                                                         {
  1111.                                                             default:
  1112.                                                                 EXECUTE(PRERR(ForceAbort,"DoImportDialog:  bad sign mode"));
  1113.                                                                 break;
  1114.                                                             case eSignSigned:
  1115.                                                                 if ((LeftValue & 0x8000) != 0)
  1116.                                                                     {
  1117.                                                                         Sample[Scan] = (LeftValue & 0x7fff) | ~0x7fff;
  1118.                                                                     }
  1119.                                                                  else
  1120.                                                                     {
  1121.                                                                         Sample[Scan] = LeftValue & 0x7fff;
  1122.                                                                     }
  1123.                                                                 if ((RightValue & 0x8000) != 0)
  1124.                                                                     {
  1125.                                                                         Sample[Scan + 1] = (RightValue & 0x7fff) | ~0x7fff;
  1126.                                                                     }
  1127.                                                                  else
  1128.                                                                     {
  1129.                                                                         Sample[Scan + 1] = RightValue & 0x7fff;
  1130.                                                                     }
  1131.                                                                 break;
  1132.                                                             case eSignUnsigned:
  1133.                                                                 Sample[Scan] = (LeftValue & 0xffff) - 32768;
  1134.                                                                 Sample[Scan + 1] = (RightValue & 0xffff) - 32768;
  1135.                                                                 break;
  1136.                                                             case eSignSignBit:
  1137.                                                                 if ((LeftValue & 0x8000) != 0)
  1138.                                                                     {
  1139.                                                                         Sample[Scan] = -(LeftValue & 0x7fff);
  1140.                                                                     }
  1141.                                                                  else
  1142.                                                                     {
  1143.                                                                         Sample[Scan] = LeftValue & 0x7fff;
  1144.                                                                     }
  1145.                                                                 if ((RightValue & 0x8000) != 0)
  1146.                                                                     {
  1147.                                                                         Sample[Scan + 1] = -(RightValue & 0x7fff);
  1148.                                                                     }
  1149.                                                                  else
  1150.                                                                     {
  1151.                                                                         Sample[Scan + 1] = RightValue & 0x7fff;
  1152.                                                                     }
  1153.                                                                 break;
  1154.                                                         }
  1155.                                                     for (Index = 0; Index < FramePadding; Index += 1)
  1156.                                                         {
  1157.                                                             unsigned char                    Stupid;
  1158.  
  1159.                                                             if (!ReadBufferedUnsignedChar(File,&Stupid))
  1160.                                                                 {
  1161.                                                                     ReleasePtr((char*)Sample);
  1162.                                                                     EndBufferedInput(File);
  1163.                                                                     AlertHalt("Unable to read from the file.",NIL);
  1164.                                                                     goto DoItFailedPoint;
  1165.                                                                 }
  1166.                                                         }
  1167.                                                 }
  1168.                                             ReturnedSampleObject = MainWindowCopyRawSampleAndOpen(MainWindow,
  1169.                                                 (char*)Sample,NumBits,NumChannels,0,0,0,0,0,0,0,
  1170.                                                 DEFAULTSAMPLINGRATE,261.625565300598635);
  1171.                                             ReleasePtr((char*)Sample);
  1172.                                         }
  1173.                                         break;
  1174.                                 }
  1175.                             break;
  1176.                     }
  1177.                 if (ReturnedSampleObject != NIL)
  1178.                     {
  1179.                         char*                    Filename;
  1180.  
  1181.                         Filename = ExtractFileName(WhereIsTheFile);
  1182.                         if (Filename != NIL)
  1183.                             {
  1184.                                 /* we don't need to release the name */
  1185.                                 SampleObjectNewName(ReturnedSampleObject,Filename);
  1186.                             }
  1187.                     }
  1188.                 EndBufferedInput(File);
  1189.  
  1190.                 /* jump here when reading in fails */
  1191.              DoItFailedPoint:
  1192.                 ;
  1193.             }
  1194.  
  1195.         DisposeRadioButton(Window->Bits8Button);
  1196.         DisposeRadioButton(Window->Bits16Button);
  1197.         DisposeRadioButton(Window->SignedButton);
  1198.         DisposeRadioButton(Window->UnsignedButton);
  1199.         DisposeRadioButton(Window->SignBitButton);
  1200.         DisposeRadioButton(Window->LittleEndian);
  1201.         DisposeRadioButton(Window->BigEndian);
  1202.         DisposeRadioButton(Window->MonoButton);
  1203.         DisposeRadioButton(Window->StereoButton);
  1204.         DisposeTextEdit(Window->BytesToSkipEdit);
  1205.         DisposeTextEdit(Window->SkipBetweenEdit);
  1206.         DisposeSimpleButton(Window->OKButton);
  1207.         DisposeSimpleButton(Window->CancelButton);
  1208.         KillWindow(Window->ScreenID);
  1209.         ReleasePtr((char*)Window);
  1210.     }
  1211.